﻿namespace Arbalest.Models.Investment
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data.Objects.DataClasses;
    using System.Runtime.Serialization;
    using System.Xml.Serialization;
    using Arbalest.Web.Controllers;

    public class Client
    {
        [DisplayName("Code")]
        [Required(ErrorMessage = "Code is required")]
        public string Code { get; set; }

        [DisplayName("Name")]
        [Required(ErrorMessage = "Name is required")]
        public string Name { get; set; }

        [DisplayName("Description")]
        public string Description { get; set; }

        [DisplayName("Client creation date")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime CreatedDate { get; set; }

        //Navigation
        public ICollection<Portfolio> Portfolios
        {
            get
            {
                DataStore ds = new DataStore();
                return ds.GetList<Portfolio>().Where(portfolio => portfolio.ClientCode == this.Code).ToList();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
    }

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Portfolio
    {
        [DisplayName("Code")]
        [Required(ErrorMessage="Code is required")]
        public string Code { get; set; }

        [DisplayName("Name")]
        [Required(ErrorMessage = "Name is required")]
        public string Name { get; set; }
        
        [DisplayName("Description")]
        public string Description { get; set; }

        [DisplayName("ClientCode")]
        [Required(ErrorMessage = "ClientCode is required")]
        public string ClientCode { get; set; }

        [DisplayName("Portfolio creation date")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime CreatedDate { get; set; }

        [DisplayName("Last correction date")]
        [Required(ErrorMessage = "Last correction date is required")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime LastCorrectionDateTime { get; set; }

        [DisplayName("Next correction date")]
        [Required(ErrorMessage = "Next correction date is required")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime NextCorrectionDateTime { get; set; }

        //Navigation
        //Client
        public Client Client
        {
            get
            {
                DataStore ds = new DataStore();
                return ds.GetList<Client>().Where(client => client.Code == this.ClientCode).FirstOrDefault();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
        //Purchases
        public ICollection<Purchase> Purchases
        {
            get
            {
                DataStore ds = new DataStore();
                return ds.GetList<Purchase>().Where(purchase => purchase.PortfolioCode == this.Code).ToList();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
    }

    public class MIC
    {
        [DisplayName("Code")]
        [Required(ErrorMessage = "Code is required")]
        public string Code { get; set; }

        [DisplayName("Name")]
        [Required(ErrorMessage = "Name is required")]
        public string Name { get; set; }
        
        //Navigation
        //Stocks
        public ICollection<Stock> Stocks
        {
            get
            {
                DataStore ds = new DataStore();
                return ds.GetList<Stock>().Where(stock => stock.MIC == this.Code).ToList();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
    }

    public class Stock
    {
        [DisplayName("MIC")]
        [Required(ErrorMessage = "MIC is required")]
        public string MIC { get; set; }

        [DisplayName("Name")]
        [Required(ErrorMessage = "Name is required")]
        public string Name { get; set; }

        [DisplayName("Code")]
        [Required(ErrorMessage = "Code is required")]
        public string Code { get; set; }

        //Navigation
        //MIC1
        public MIC MIC_MIC
        {
            get
            {
                DataStore ds = new DataStore();
                return ds.GetList<MIC>().Where(mic => mic.Code == this.MIC).FirstOrDefault();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
        //Purchases
        public ICollection<Purchase> Purchases
        {
            get
            {
                DataStore ds = new DataStore();
                return ds.GetList<Purchase>().Where(purchase => purchase.MIC == this.MIC).ToList();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
    }

    public class Purchase
    {
        [DisplayName("Id")]
        public long Id { get; set; }

        [DisplayName("Portfolio code")]
        [Required(ErrorMessage = "Portfolio code is required")]
        public string PortfolioCode { get; set; }

        [DisplayName("MIC")]
        [Required(ErrorMessage = "MIC is required")]
        public string MIC { get; set; }

        [DisplayName("Code")]
        [Required(ErrorMessage = "Code is required")]
        public string Code { get; set; }

        [DisplayName("Quantity")]
        [Required(ErrorMessage = "Quantity is required")]
        public decimal Quantity{ get; set; }

        [DisplayName("Price")]
        [Required(ErrorMessage = "Price is required")]
        public decimal Price { get; set; }

        [DisplayName("Date")]
        [Required(ErrorMessage = "Date is required")]
        public DateTime Date { get; set; }

        //Navigation
        //Portfolio
        //Stock
    }


}